package com.liuzh.deviceinfo.view.kv;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.cardview.widget.CardView;
import c.h.a.m0.h;
import c.h.a.n0.h.b;
import c.h.a.n0.h.c;
import java.util.List;

public class KvCard extends CardView {
    public LinearLayout j;
    public final int k;
    public a l;
    public TextView m;

    public interface a {
    }

    public KvCard(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        int t = h.t(7.0f, getResources().getDisplayMetrics());
        this.k = t;
        setUseCompatPadding(true);
        LinearLayout linearLayout = new LinearLayout(getContext());
        this.j = linearLayout;
        linearLayout.setOrientation(1);
        this.j.setPadding(0, 0, 0, t);
        addView(this.j);
    }

    public void d(String str, List<c> list) {
        if (this.j.getChildCount() == 0) {
            e(str, list);
            return;
        }
        if (this.m != null) {
            if (TextUtils.isEmpty(str)) {
                this.m.setVisibility(8);
            } else {
                this.m.setText(str);
            }
        }
        for (c cVar : list) {
            View findViewWithTag = this.j.findViewWithTag(cVar.a);
            if (findViewWithTag != null) {
                TextView textView = (TextView) findViewWithTag.findViewById(2131296753);
                TextView textView2 = (TextView) findViewWithTag.findViewById(2131297325);
                textView.setText(cVar.a);
                textView2.setText(cVar.b);
                textView2.setFocusable(true);
                String[] strArr = cVar.c;
                if (strArr == null || strArr.length <= 0) {
                    textView2.setOnClickListener(null);
                    textView2.setTextIsSelectable(true);
                    textView2.setBackground(null);
                } else {
                    textView2.setTextIsSelectable(false);
                    textView2.setOnClickListener(new c.h.a.n0.h.a(this, cVar));
                    textView2.setBackground(c.f.a.a.a.a.o(getContext(), 16843534));
                }
            }
        }
    }

    public void e(String str, List<c> list) {
        this.j.removeAllViews();
        LayoutInflater from = LayoutInflater.from(getContext());
        this.m = (TextView) from.inflate(2131493000, this.j, false);
        if (TextUtils.isEmpty(str)) {
            this.m.setVisibility(8);
        } else {
            this.m.setText(str);
        }
        this.j.addView(this.m);
        for (c cVar : list) {
            View inflate = from.inflate(2131492999, this.j, false);
            TextView textView = (TextView) inflate.findViewById(2131296753);
            TextView textView2 = (TextView) inflate.findViewById(2131297325);
            inflate.setTag(cVar.a);
            textView.setText(cVar.a);
            textView2.setText(cVar.b);
            textView2.setFocusable(true);
            String[] strArr = cVar.c;
            if (strArr == null || strArr.length <= 0) {
                textView2.setOnClickListener(null);
                textView2.setTextIsSelectable(true);
                textView2.setBackground(null);
            } else {
                textView2.setTextIsSelectable(false);
                textView2.setOnClickListener(new b(this, cVar));
                textView2.setBackground(c.f.a.a.a.a.o(getContext(), 16843534));
            }
            this.j.addView(inflate);
        }
    }

    public int getKVCount() {
        int childCount = this.j.getChildCount();
        return childCount == 0 ? 0 : childCount - 1;
    }

    public void setPermissionRequester(a aVar) {
        this.l = aVar;
    }
}
